#ifndef SIGNALMAINPAGE_H
#define SIGNALMAINPAGE_H

#include <QWidget>
#include <QTimer>
#include <QDateTime>
#include <QFile>
#include <QHash>
#include <QTableWidget>
#include <QLabel>
#include "globalconfig.h"
#include "numberkeyboarddialog.h"
#include "dashboard2.h"
#include "scalewidget.h"
#include "signalpopmenu.h"
#ifdef M1515
#include "M1515/audio_play.h"
#include "M1515/hi_type.h"
#include "M1515/hisi_dev.h"
#endif

namespace Ui {
class SignalMainpage;
}

class SignalMainpage : public QWidget
{
    Q_OBJECT

public:
    explicit SignalMainpage(QWidget *parent = 0);
    ~SignalMainpage();
    void Set_ATC_ComFlt_Page(bool xcomflt);
    void flush_ATC_ComFlt_Info(bool atpfs,int speed);
    //M5
    void set_M5_DoorStat(uint8_t stat);
    void set_M5_DoorOpenPermitMode(uint8_t mode);
    void set_M5_DoorForcePermit(uint8_t cmd);
    void set_M5_Stat(uint8_t door_stat,uint8_t door_mode,uint8_t force_permit_cmd);
    //M1
    void set_M1_Stat(uint8_t atp_system_mode);
    //M8
    void set_M8_RightPSDStat(uint8_t stat);
    void set_M8_LeftPSDStat(uint8_t stat);
    void set_M8_IdlingSlipStat(uint8_t stat);
    void set_M8_EBStat(uint8_t stat);
    void set_M8_Stat(uint8_t rpsd_stat,uint8_t lpsd_stat,uint8_t idling_slip,uint8_t eb);
    //A1
    void set_A1_Stat(uint8_t eb_stat, uint8_t mode, uint8_t speed, uint8_t rec_speed);
    //M10
    void set_M10_LocationStat(uint8_t stat);
    void set_M10_DepotStat(uint8_t stat);
    void set_M10_TrainFireStat(bool stat);
    void set_M10_ReleaseSpeedStat(bool stat);
    void set_M10_Stat(uint8_t is_located, uint8_t depot_stat, bool fire, bool release_speed);
    //超速报警触发声音
    void set_Sound_OverSpeed_Stat(uint8_t stat);
    void try_play_sound();
    //F区
    void set_F_Message_Text(bool xtrigger,const QString &text);
    int  decide_need_show_text_F(QString &show_text);
    void update_F_Text();
    void set_F_PreSelectStat(uint8_t stat);
    void set_F_BackToDepotHint(uint8_t hint);
    void set_F_ConfirmRunInRM(uint8_t mode);
    void set_F_SpeedReleaseStat(uint8_t stat);
    void set_F_EnterRainOrSnowMode(bool xhint);
    void set_F_LocalTrainNumber(uint32_t number);
    void set_F_TrainNumberErrorIndication(uint8_t indication);
    void set_F_VIDCheckStat(uint8_t stat);
    void set_F_EBTestStat(uint8_t eb_test);
    void set_F_EBTestFailedCode(uint8_t code);
    void indicate_F_EscapeDoorOpen(bool xopen);
    void indicate_F_SalDoorUnlocked(bool xunlock);
    void indicate_F_RunTimeTooLong(uint8_t warning);
    void remind_F_DriverTakeOffKey(uint8_t reminder);
    void set_F_ATPWakeUpFeedBackStat(uint8_t stat);
    void indicate_F_WheelCalibrationFail(bool xfail);
    void set_F_PassengerPullEmergencyHandle(bool xpull);
    void set_F_TrainSleepFailed(uint8_t fail);
    void indicate_F_QuitFAMMode(uint8_t fail);
    void indicate_F_UpGradeToFAMMode(uint8_t fail);
    void indicate_F_TempSpeedLimit(bool xtrig);
    void set_F_BackWardSelect(uint8_t stat);
    void set_F_ForWardSelect(uint8_t stat);
    //超速声音报警
    void Over_speed_Sound_Tirgger(uint8_t over_speed);
    void Play_ATC_Sound(bool xPlay);
    //C2
    void set_C2_CurrentPreSelectMode(uint8_t mode);
    //M4
    void set_M4_OutParkAreaStat(uint8_t stat);
    //M2
    void set_M2_CurrentRunLevel(uint8_t level);
    void set_M2_Stat(uint8_t mode,uint8_t level);
    //C4
    void set_C4_CutOffTractionStat(uint8_t stat);
    void set_C4_LackOfBrkEffortStat(bool stat);
    void set_C4_RainAndSnowStat(bool stat);
    void set_C4_Stat(uint8_t cut_traciton,bool low_brk_effort,bool rain_snow);
    //C3
    void set_C3_TrainIntegrityStat(uint8_t stat);
    //G3
    void set_G3_ZCConnectionStat(uint8_t stat);
    void set_G3_CIConnectionStat(uint8_t stat);
    void set_G3_ATSConnectionStat(uint8_t stat);
    //C5
    void set_C5_ATCDeviceStat(uint8_t stat);
    //M9
    void set_M9_ATCSystemFltStat(uint8_t stat);
    //M6
    void set_M6_DepartHintStat(uint8_t stat);
    void set_M6_DoorCloseHintStat(uint8_t stat);
    void set_M6_stat(uint8_t atc_system_mode,uint8_t depart_hint,uint8_t door_close_hint);
    //M7
    void set_M7_DoorControlMode(uint8_t mode);
    void set_M7_Stat(uint8_t atc_system_mode, uint8_t door_ctrl_mode);
    //C1
    void set_C1_ATOTracBrkStat(uint8_t stat);
    void set_C1_Stat(uint8_t atc_system_mode,uint8_t trac_brk_stat);
    //N
    void set_N_GoIndicationStat(uint8_t stat);
    void set_N_ClearPassengersStat(uint8_t stat);
    void set_N_NoGoIndicationStat(uint8_t stat);
    void set_N_DTITimeCountType(uint8_t type);
    void set_N_DTITimeCount(uint16_t count);
    void set_N_stat(uint8_t atc_system_mode,uint8_t go_ind,uint8_t no_go_ind,uint8_t clear_psg,uint8_t tc_type,uint16_t time_cout);
    //E
    void setUnReleasedEBStat(bool xtrig);
    void setEBCode(uint32_t code);
    void set_E_Text(bool unreleased_eb,uint32_t eb_code);
    void readATCEMsgInfo(QString path);
    //M3
    void set_M3_stat(uint8_t revert_stat);
    //Menu
    void set_Menu_RCS_Test_Stat(uint8_t stat);
    //柱状图及仪表盘
    void setTargetDistance(uint16_t distance);
    void updateTargetDistanceStat(uint8_t atc_system_mode,uint16_t distance);
    void setTargetSpeed(uint8_t speed);
    void updateTargetSpeedStat(uint8_t atc_system_mode,uint16_t speed);
    void setTrainSpeed(uint8_t speed);
    void setRestritSpeed(uint8_t restrit_speed);//红标
    void setRecSpeedvalue(uint8_t rec_speed);//黄标
    //C6
    void set_C6_TrainStopDeviation(uint16_t val);

    SignalPopMenu* Menu() const;
private slots:
    //F区
    void slot_New_Message();
    void slot_timerout();
    void on_Btn_Menu_clicked();
    //M3
    void slot_M3_flash();
private:
    Ui::SignalMainpage *ui;
    ScaleWidget *target_distance_bar_=nullptr;
    DashBoard2 *dashboard_=nullptr;
    QLabel *atc_comflt_page_=nullptr;
    QTimer *atp_eb_success_timer_=nullptr;
    QList<QLabel*> atc_all_stat_labels_;
    SignalPopMenu *atc_pop_menu_=nullptr;
    void setRecSpeed(uint8_t mode,uint8_t rec_speed);//黄标
private:
    void InitSound();
    void enterStandByMode(bool set_mode);
private:
    //M5
    uint8_t  signal_1_M5_door_stat_=0;
    uint8_t  signal_9_M5_door_mode_=0;
    uint8_t  signal_16_M5_door_force_permit_=0;
    //M1
    uint8_t  signal_0_M1_atp_system_mode_=0;
    //M8
    uint8_t  signal_2_M8_right_PSD_stat_=0;
    uint8_t  signal_3_M8_left_PSD_stat_=0;
    uint8_t  signal_11_M8_idling_slip_=0;
    //A1
    uint8_t  signal_28_A1_EB_=0;
    //M10
    uint8_t  signal_4_M10_islocated_=0;
    uint8_t  signal_14_M10_depot_=0;
    bool     signal_21_M10_train_fire_=false;
    bool     signal_20_M10_release_speed_=false;
    //F区
    QTimer   *new_message_timer_=nullptr;

    uint8_t  signal_78_F_local_sleep_=0;
    uint8_t  signal_77_F_runtime_toolong_=0;
    bool     signal_76_F_unlock_door_=false;
    bool     signal_75_F_escape_door_open_=false;
    uint8_t  signal_84_F_upgrade_FAM_=0;
    uint8_t  signal_83_F_quit_FAM_=0;
    uint8_t  signal_82_F_sleep_failed_=0;
    uint8_t  signal_79_F_wakeup_feedback_=0;
    bool     signal_88_F_temporary_speed_limit_=false;
    bool     signal_81_F_passenger_pull_em_handle_=false;
    bool     signal_80_F_wheel_calibration_failed_=false;
    uint8_t  signal_89_F_backward_select_=0;
    uint8_t  signal_90_F_forward_select_=0;
    uint8_t  signal_73_F_EB_test_=0;
    uint8_t  pre_73_F_EB_test_=0;
    uint8_t  signal_74_F_EB_test_fail_code_=0;
    uint8_t  signal_13_F_back_to_depot_hint_=0;
    uint8_t  signal_22_F_speed_release_=0;
    uint8_t  signal_23_F_confirm_RM_=0;
    bool     signal_30_F_hint_rain_snow_=false;
    uint32_t signal_68_F_local_train_number_=0;
    uint8_t  signal_69_F_train_number_error_=0;
    uint8_t  signal_70_F_VID_error_code_=0;
    uint8_t  signal_7_F_is_preselecting_=0;
    //超速报警触发声音
    uint8_t  signal_5_Sound_overspeed_=0;
    //C2
    uint8_t  signal_6_C2_current_preselect_mode_=0;
    //M4
    uint8_t  signal_10_M4_out_of_park_area_=0;
    //M2
    uint8_t  signal_15_M2_current_run_level_=0;
    //C4
    uint8_t  signal_25_C4_cutoff_traction_=0;
    bool     signal_26_C4_lack_of_brake_effort_=false;
    bool     signal_27_C4_rain_and_snow_=false;
    //C3
    uint8_t  signal_31_C3_train_integrity_=0;
    //G3
    uint8_t  signal_33_G3_ZC_connection_=0;
    uint8_t  signal_34_G3_CI_connection_=0;
    uint8_t  signal_35_G3_ATS_connection_=0;
    //C5
    uint8_t  signal_37_C5_ATC_device_stat_=0;
    //C6
    int16_t  signal_107_C6_stop_deviation_=0;
    //M9
    uint8_t  signal_39_M9_ATC_systemflt_=0;
    //柱状图及仪表盘
    uint16_t signal_44_target_distance_=0;
    uint8_t  signal_43_target_speed_=0;
    uint8_t  signal_45_train_speed_=0;
    uint8_t  signal_46_restrict_speed_=0;
    uint8_t  signal_47_rec_speed_=0;
    //M6
    uint8_t  signal_56_M6_depart_hint_=0;
    uint8_t  signal_62_M6_door_close_hint_=0;
    //M7
    uint8_t  signal_55_M7_door_control_mode_=0;
    //C1
    uint8_t  signal_60_C1_ATO_trac_brk_stat_=0;
    //N
    uint8_t  signal_59_N_go_indication_=0;
    uint8_t  signal_58_N_clear_passengers_=0;
    uint8_t  signal_61_N_no_go_indication_=0;
    uint8_t  signal_91_N_DTI_time_count_type_=0;
    uint16_t signal_92_N_DTI_time_count_=0;
    //E区
    bool     signal_105_E_unreleased_EB_=false;
    uint32_t signal_40_E_EB_code_=0;
    QHash<int,QString> hash_code_msg_;//信号代码与描述关系
    //M3
    uint8_t  signal_12_M3_Revert_stat_=0;
    QTimer   *m3_flash_timer_=nullptr;
    //Menu
    uint8_t  signal_41_Menu_RCS_test_ = 0;
};

#endif // SIGNALMAINPAGE_H
